//package java_cup;

/**
 * This class represents one part (either a SymbolDraft or an actionPart) of a
 * production. In this base class it contains only an optional label string that
 * the user can use to refer to the part within actions.
 * <p>
 *
 * This is an abstract class.
 *
 * @see java_cup.production
 * @version last updated: 11/25/95
 * @author Scott Hudson
 */
public abstract class ProductionPart {

    /*-----------------------------------------------------------*/
    /*--- Constructor(s) ----------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Simple constructor. */
    public ProductionPart(String label) {
        _label = label;
    }

    /*-----------------------------------------------------------*/
    /*--- (Access to) Instance Variables ------------------------*/
    /*-----------------------------------------------------------*/

    /**
     * Optional label for referring to the part within an actionPart (null for no
     * label).
     */
    public String _label;

    /**
     * Optional label for referring to the part within an actionPart (null for no
     * label).
     */
    public String Label => _label;

    /*-----------------------------------------------------------*/
    /*--- General Methods ---------------------------------------*/
    /*-----------------------------------------------------------*/

    /**
     * Indicate if this is an actionPart (rather than a SymbolDraft). Here in the base class,
     * we don't this know yet, so its an abstract method.
     */
    public abstract bool IsAction { get; }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Equality comparison. */
    public bool equals(ProductionPart other) {
        if (other == null)
            return false;

        /* compare the labels */
        if (Label != null)
            return Label.Equals(other.Label);
        else
            return other.Label == null;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Generic equality comparison. */
    /*@Override*/
    public override bool Equals(Object? other) {
        if (!(other is ProductionPart))
            return false;
        else
            return equals((ProductionPart)other);
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Produce a hash code. */
    /*@Override*/
    public override int GetHashCode() {
        return Label == null ? 0 : Label.GetHashCode();
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Convert to a string. */
    /*@Override*/
    public override string ToString() {
        if (Label != null)
            return Label + ":";
        else
            return " ";
    }

    /*-----------------------------------------------------------*/

}
